/*------------------------------------------------------------------------------------------------\
| Horrible X-Wing game by Steven Haber
| st_haber@hotmail.com
|
| score.cpp: Contains the score class which tracks and displays the score for the players.
\------------------------------------------------------------------------------------------------*/

#include "Score.h"


//Constructiod
Score::Score(sf::RenderWindow *out, int posX)
{
	mScore = 0;

	mOut = out;
	
	mScoreString.SetFont("font.ttf");
	mScoreString.SetSize(20);
	mScoreString.SetText(MAXSCORESTRING);
	mScoreString.SetTop((float)posX);

	mRect = new sf::Rect<float>(mScoreString.GetRect());
}


//Adds to the score!
void Score::addToScore(int value)
{
	mScore += value;
	if(mScore > MAXSCORE)
		mScore = 0;
}


//Draws the score
void Score::drawScore()
{
	std::ostringstream streamy;
	
	for(int i = 0; i < SCOREDIGITS; i++)
	{
		if(mScore < pow((float)10, i))
			streamy << '0';
	}
	if(mScore > 0)
		streamy << mScore;

	std::string stringy = streamy.str();
	mScoreString.SetText(stringy);

	mOut->Draw(mScoreString);
}


//Sets the left
void Score::setLeft(int left)
{
	mScoreString.SetLeft((float)left);
}


//Returns the width
int Score::getWidth()
{
	return (int)mRect->GetWidth();
}